import { AxiosQ } from "./http"
import { getCompany_id } from "./login"
import { deviceType } from "./types"
import { Url } from "./url"

export const apirotatingGet = () => {
 return AxiosQ('GET', Url.rotating, {
  params: {
   company_id: getCompany_id()
  }
 })
}

export const apiUploadPost = (_file: File, updateProgress: any) => {
 return AxiosQ("POST", Url.upload, {
  data: {
   file: _file,
   isRept: false,
  },
  headers: {
   "Content-Type": "multipart/form-data",
  },
  onUploadProgress: updateProgress,
 })
}

export const apiRotaringPost = (url: string) => {
 return AxiosQ('POST', Url.rotating, {
  data: {
   company_id: getCompany_id(),
   url: url
  }
 })
}

export const apiRotatingDelete = (id: number) => {
 return AxiosQ('DELETE', Url.rotating, { data: { company_id: getCompany_id(), id: id } })
}

export const apiMenuGet = () => {
 return AxiosQ('GET', Url.menu, {
  params: {
   company_id: getCompany_id()
  }
 })
}

export const apiMenuPost = (menuItem: any) => {
 return AxiosQ('POST', Url.menu, {
  data: {
   company_id: getCompany_id(),
   ...menuItem
  }
 })
}

export const apiMenuPut = (id: number, menuItem: any) => {
 return AxiosQ('PUT', Url.menu, {
  data: {
   company_id: getCompany_id(),
   id,
   ...menuItem
  }
 })
}

export const apiMenuDelete = (id: number) => {
 return AxiosQ('DELETE', Url.menu, {
  data: {
   company_id: getCompany_id(),
   id: id
  }
 })
}


export const apiDeviceGet = (file_id: number) => {
 return AxiosQ('GET', Url.device, { params: { file_id, company_id: getCompany_id() } })
}

export const apiDevicePost = (deviceItem: deviceType) => {
 return AxiosQ('POST', Url.device, { data: { company_id: getCompany_id(), ...deviceItem } })
}
export const apiDevicePut = (deviceItem: deviceType) => { 
 return AxiosQ('put', Url.device, { data: { company_id: getCompany_id(), ...deviceItem } })
}
export const apiDeviceDelete = (id: number) => {
 return AxiosQ('DELETE', Url.device, { data: { company_id: getCompany_id(), id: id } })
}